'''built_in'''
import tkinter
import tkinter.filedialog as filedialog

'''# custom'''
from common import GSDSTORE


class win(object):

    def __repr__(self) -> str:
        return "窗口控件事件类"
    
    def __init__(self) -> None:
        return
    
    def __call__(self, eel) -> None:

        @eel.expose
        def run_termination():
            """终止程序运行"""
            quit()  # 终止程序运行

        @eel.expose
        def set_explorer():
            """打开资源管理器，选择文件夹路径"""
            try:
                root = tkinter.Tk()
                root.attributes("-topmost", True)
                root.withdraw()
            except Exception as error:
                return False
            else:
                directory_path = filedialog.askdirectory()
                return directory_path.replace('/', '\\')
        
        @eel.expose
        def run_start(packetPath, modular, parameter):
            """
             开始框架执行

             参数：
                @param packetPath : 用例数据包路径
                @param modular : 待执行测试用例文件
                @param parameter : 框架启动参数
            """
            
            if packetPath and modular and parameter:
                GSDSTORE['START']['packetPath'] = packetPath
                GSDSTORE['START']['testCaseFile'] = modular
                GSDSTORE['START']['browser'] = parameter['browser']
                GSDSTORE['START']['url'] = parameter['url']
                GSDSTORE['START']['implicitlyWait'] = parameter['implicitlyWait']
                GSDSTORE['START']['user'] = parameter['user']
                GSDSTORE['START']['password'] = parameter['password']
                GSDSTORE['START']['pluginName'] = parameter['pluginName']
                GSDSTORE['START']['interfaceSwitch'] = parameter['interfaceSwitch']
                GSDSTORE['START']['codeSwitch'] = parameter['codeSwitch']
                GSDSTORE['START']['retrySwitch'] = parameter['retrySwitch']
            else:
                print("可视化窗口配置值获取失败！")
                raise Exception